<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>拒绝服务通知</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		<style type="text/css">
			.mui-input-group{
				    margin: 0 20px 0 0;
				    position: initial;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">拒绝服务通知</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div class="clum">
					<span class="name">服务编号</span>
					<span class="txt" id="serviceNo"></span>
				</div>
				<div class="clum" style="border-bottom:0;">
				<span class="name">拒绝理由</span>
				</div>
				<form class="mui-input-group" id="jujue">
					<!-- <div id="jujue">
						<div class="mui-input-row mui-checkbox mui-left">
							<label>没时间</label>
							<input name="checkbox" value="理由一" type="checkbox" >
						</div>
						<div class="mui-input-row mui-checkbox mui-left">
							<label>有其他任务</label>
							<input name="checkbox" value="理由二" type="checkbox">
						</div>
						<div class="mui-input-row mui-checkbox mui-left">
							<label>不喜欢这个客户</label>
							<input name="checkbox" value="理由三" type="checkbox">
						</div>
					</div> -->
					
				</form>
				<div class="clum autoHeight">
					<span class="name">其他</span>
					<div class="clear"></div>
					<textarea id="refuse" class="textarea" placeholder="请输入内容最多100字"></textarea>
				</div>
			</div>
			<div class="btn_box">
				<span class="fl" id="cancel">取消</span>
				<span class="fr red" id="save">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/utils/rolldate.min.js"></script>
		
		<script type="text/javascript" charset="utf-8">
			var ServiceNoticeId;
			var serviceNo;
			var planId;
			
			 //mui初始化
			(function($, doc) {
				$.init();
				
				// 取消方法
				h("#cancel").tap(function(){
					$.back()
				});
				
				$.plusReady(function() {
					
					// 查询拒绝理由字典
					selectDict();
					
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					 // 获取上一个页面传过来的参数并显示到页面
					 ServiceNoticeId = self.ServiceNoticeId;
					 serviceNo = self.serviceNo;
					 planId = self.planId;

					h("#serviceNo").html(serviceNo)
					
					// 保存
					h("#save").tap(function() {
						app.showWaiting('正在提交...')
						var checkboxtext = "";
						// 获取checkbox的值
						var ele = document.getElementsByName("checkbox");
						for (var i = 0; i < ele.length; i++) {
							console.log(ele[i].value + ": " + ele[i].checked)
							if(ele[i].checked){
								if(checkboxtext==undefined || checkboxtext=="undefined" || checkboxtext==""){
									checkboxtext += ele[i].value;
								}else{
									checkboxtext += "," + ele[i].value;
								}
							}
						}
						var refuseText = h("#refuse").val();
						if(refuseText!=undefined && refuseText!=''){
							if(refuseText.length>100){
								app.closeWaiting()
								app.toast("其它内容最多100个字");
								return
							}
						}
						if(checkboxtext==undefined || checkboxtext=="undefined" || checkboxtext==""){
							checkboxtext += refuseText;
						}else{
							checkboxtext += "," + refuseText;
						}
						console.log("checkboxtext："+checkboxtext)
						if(checkboxtext==undefined || checkboxtext=="undefined" || checkboxtext==""){
							app.closeWaiting()
							app.toast("请选择或输入拒绝理由");
							return
						}
						
						ajaxPost(BASE_URL + "cc/PlanDetails/fseRefuse", {
							"serviceNoticeId": ServiceNoticeId,
							"serviceNo": serviceNo,
							"fseId": app.getUser().enginnerId,
							"fseName": app.getUser().name,
							"refusalReasons": checkboxtext,
							"planId": planId
						}, function(data) {
							app.closeWaiting()
							console.log(JSON.stringify(data))
							if(data.code==200){
								app.toast("操作成功");
								
								// 查找上级页面并关闭页面
								var details = plus.webview.getWebviewById('view/service/accept/details.html');
								if (details) {
									details.close()
								}
								// 查找需要跳转的页面，并指定刷新的方法
								var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
								if(indexFSE){
									indexFSE.evalJS('getList("0")')
								}
								
								// 刷新TL首页
								var indexTl=plus.webview.getWebviewById('view/main/indexTL.html');
								if(indexTl){
								    indexTl.evalJS('getMyTeamCount()')
								}
								
								// 刷新 工作台服务通知数量
								var noticeMenu=plus.webview.getWebviewById('view/service/notice/noticeMenu.html');
								if(noticeMenu){
									noticeMenu.evalJS('getNoticeCount()')
								}
								
								var acceptList = plus.webview.getWebviewById('view/service/assign/acceptList.html');
								if (acceptList) {
									acceptList.close()
								}
								
								// 关闭工作台待接受列表
								var toBeAcceptedList = plus.webview.getWebviewById('view/service/notice/toBeAcceptedList.html');
								if(toBeAcceptedList){
									toBeAcceptedList.close()
								}
								
								// 关闭进行中
								var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
								if(conductList){
									conductList.close()
								}
								
								// 关闭工作台查询未关闭服务通知列表
								var notClosedList = plus.webview.getWebviewById('view/service/notice/notClosedList.html');
								if(notClosedList){
									notClosedList.close()
								}
								
								// 查找需要跳转的页面，并指定刷新的方法
								var assignList = plus.webview.getWebviewById('view/service/notice/toBeAcceptedList.html');
								if(assignList){
									assignList.evalJS('getList()')
									$.back()
								}else{
									var acceptedList = plus.webview.create('/view/service/notice/toBeAcceptedList.html','view/service/notice/toBeAcceptedList.html')
									acceptedList.show()
									self.close()
								}	
								
							}
						}, function(errorMsg) {
							console.log(JSON.stringify(errorMsg))
						});
						
					});
					
				});
				
				
				
			}(mui, document));
			
			// 查询拒绝理由字典
			function selectDict(){
				ajaxGet(BASE_URL + "cc/dict/selectDict", {
					"dictType": "refusal_reasons"
				}, function(data) {
					// console.log(JSON.stringify(data))
					if(data.code==200){
						var html = "";
						h("#jujue").html(html);
						for(var i=0;i<data.data.length;i++){
							
							var d = data.data[i];
							html += '<div class="mui-input-row mui-checkbox mui-left">'
							html += '<label style="font-size:15px;">'+d.dictLabel+'</label>'
							html += '<input name="checkbox" value="'+d.dictLabel+'" type="checkbox">'
							html += '</div>';
						}
						h("#jujue").html(html);
					}
				}, function(errorMsg) {
					console.log(JSON.stringify(errorMsg))
				});
			}
			
		</script>
		<!-- js代码 end -->

	</body>

</html>
